/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ymtweet;

import java.io.IOException;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.User;
import util.Log;
import ymsg.network.LoginRefusedException;
import ymsg.network.Session;
import ymsg.network.event.SessionAuthorizationEvent;
import ymsg.network.event.SessionChatEvent;
import ymsg.network.event.SessionConferenceEvent;
import ymsg.network.event.SessionErrorEvent;
import ymsg.network.event.SessionEvent;
import ymsg.network.event.SessionExceptionEvent;
import ymsg.network.event.SessionFileTransferEvent;
import ymsg.network.event.SessionFriendEvent;
import ymsg.network.event.SessionListener;
import ymsg.network.event.SessionNewMailEvent;
import ymsg.network.event.SessionNotifyEvent;
import ymsg.network.event.SessionPictureEvent;

/**
 *
 * @author leswide
 */
public class Main implements SessionListener {

    private Hashtable table = new Hashtable<String, User>();
    private Session session;
    private boolean loginStatus = false;

    public Main() {
        session = new Session();
        session.addSessionListener(this);
        login("ymtweet", "asdf1234");
    }

    public void login(String username, String password) {
        loginStatus = false;
        try {
            session.login(username, password);
            loginStatus = true;
            Log.print("loging in...");
        } catch (IllegalStateException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LoginRefusedException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    public boolean isLoginStatus() {
        return loginStatus;
    }

    public void setLoginStatus(boolean loginStatus) {
        this.loginStatus = loginStatus;
    }

    public synchronized Session getSession() {
        return session;
    }

    public void setSession(Session session) {
        this.session = session;
    }

    public synchronized Hashtable getTable() {
        return table;
    }

    public void setTable(Hashtable table) {
        this.table = table;
    }

    public void messageReceived(SessionEvent se) {
        //terima pesan
        Log.print("receive msg from : " + se.getFrom());
        new TwitterThread(this, se).start();
    }

    public void fileTransferReceived(SessionFileTransferEvent sfte) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void connectionClosed(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void listReceived(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void buzzReceived(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void offlineMessageReceived(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void errorPacketReceived(SessionErrorEvent see) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void inputExceptionThrown(SessionExceptionEvent see) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void newMailReceived(SessionNewMailEvent snme) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void notifyReceived(SessionNotifyEvent sne) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void contactRequestReceived(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void contactRejectionReceived(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void conferenceInviteReceived(SessionConferenceEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void conferenceInviteDeclinedReceived(SessionConferenceEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void conferenceLogonReceived(SessionConferenceEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void conferenceLogoffReceived(SessionConferenceEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void conferenceMessageReceived(SessionConferenceEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void friendsUpdateReceived(SessionFriendEvent sfe) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void friendAddedReceived(SessionFriendEvent sfe) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void friendRemovedReceived(SessionFriendEvent sfe) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void chatLogonReceived(SessionChatEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void chatLogoffReceived(SessionChatEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void chatMessageReceived(SessionChatEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void chatUserUpdateReceived(SessionChatEvent sce) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void chatConnectionClosed(SessionEvent se) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void pictureReceived(SessionPictureEvent spe) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void authorizationReceived(SessionAuthorizationEvent sae) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }
}
